<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <title>库存查询</title>
</head>
<body>
<table class="table table-striped table-bordered table-hover" id="sample-table">
    <thead>
    <tr>
        <th width="90px">序号</th>
        <th width="120px">商品编号</th>
        <th width="120px">商品名称</th>
        <th width="120px">仓库编号</th>
        <th width="120px">仓库名称</th>
        <th width="120px">单位</th>
        <th width="120px">现有数量</th>
        <th width="200px">操作</th>
    </tr>
    </thead>
    <tbody>
    </tbody>
</table>
<script type="text/javascript">
    jQuery(function ($) {
        $.ajax({
            url: '/warehouse/list',
            type:'post',
            success:function (res) {
                for (var i= 0;i<res.length;i++){
                    $("#warehouseName").append('<option value="'+res[i].warehouseName+'">'+res[i].warehouseName+'</option>')
                }
            }
        })

        var table = $('#sample-table').DataTable({
            aLengthMenu: [5, 10, 15, 20, 50, 100], //更改显示记录数选项
            "ordering": false,
            bFilter: false, //是否启动过滤、搜索功能
            iDisplayLength: 5, //默认显示的记录数
            "serverSide": true, // true表示使用后台分页
            cache:false,
            "bStateSave": false,//状态保存
            'autoWidth': true,
            "ajax": {
                "url": "/warehouse/inventory",  // 异步传输的后端接口url
                "type": "POST",
                dataSrc: "data",
                data: function (d) {
                    var param = {};
                    param.wId = '[[${param.wId}]]';
                    param.draw = d.draw;
                    param.start = d.start;
                    param.length = d.length;
                    var formData = $("#formData").serializeArray();//把form里面的数据序列化成数组
                    formData.forEach(function (e) {
                        param[e.name] = e.value;
                    });
                    return param;//自定义需要传递的参数。
                },
            },
            "columns": [
                {"data": "id"},
                {"data": "pid"},
                {"data": "productName"},
                {"data": "warehouseNo"},
                {"data": "warehouseName"},
                {"data": null,
                    "createdCell": function (td, cellData, rowData, row, col) {
                        $(td).empty().append('<span>pc</span>');
                    }},
                {"data": "num"},
                {
                    "data": "id",
                    "createdCell": function (td, cellData, rowData, row, col) {
                        $(td).empty().append(' <a title="查看详情" value="' + row + '" class="btn btn-xs btn-info property_edit" ><i class="icon-list bigger-120"></i></a>');
                    }
                },
            ]
        });


        //查看详情
        $('table').on('click', '.property_edit', function () {
            var index = $(this).attr('value');
            var data = table.row(index).data();

            console.log($.param(data));
            layer.open({
                type: 2,
                title: '查看详情',
                shadeClose: false,
                maxmin: true, //开启最大化最小化按钮
                area: ['600px', '590px'],
                content: '/warehouse/Inventory_check/Inventory_detailPage?' + $.param(data)
            });
        })
        $("#btn").click(function () {
            table.ajax.reload();
        });

    });
</script>
</body>
</html>



